﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using MTO.Framework.Common;

namespace MTO.Framework.DirectoryServices.Helpers
{
    public static class ConnectionHelper
    {
        public static void GetInfosFromConnectionString(string connectionString, out string serverName, out string container, out bool useSSL)
        {
            var match = Regex.Match(connectionString, RegexStrings.LDAPConnectionString);
            if (!match.Success || match.Groups.Count != 4)
            {
                throw new ArgumentException("The provided connection string is not an LDAP connection string : " + connectionString);
            }
            useSSL = match.Groups[1].Value == "LDAPS";
            serverName = match.Groups[2].Value;
            container = match.Groups[3].Value;
        }
    }
}
